#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pp;
int n, k;
const int N = 5 * 1e5 + 10;
bool st[N];
int arr[N];
int prevarr[N];
int nextarr[N];
template <class T>
class compare
{
public:
    bool operator()(const T &a, const T &b)
    {
        if (a.first != b.first)
        {
            return a.first > b.first;
        }
        else
        {
            return a.second > b.second;
        }
    }
};
priority_queue<pp, vector<pp>, compare<pp>> q;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        prevarr[i] = i - 1;
        nextarr[i] = i + 1;
        q.push(make_pair(arr[i], i));
    }
    nextarr[n - 1] = -1;
    while (k)
    {
        pp tem = q.top();
        q.pop();
        int curind = tem.second;
        if (!st[curind] && tem.first == arr[curind])
        {
            // 如果当前数没有被删除过并且要删除的数不是老数据
            k--;
            st[curind] = true;
            int left = prevarr[curind];
            int right = nextarr[curind];
            if (right != -1)
            {
                arr[right] += tem.first;
                q.push(make_pair(arr[right], right));
            }
            if (left != -1)
            {
                arr[left] += tem.first;
                q.push(make_pair(arr[left], left));
            }
            if(left==-1)
            {
                //说明是头部删除
                prevarr[right]=-1;
            }
            else if(right==-1)
            {
                nextarr[left]=-1;
            }
            else
            {
                nextarr[left]=right;
                prevarr[right]=left;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (!st[i])
            cout << arr[i] << " ";
    }
    return 0;
}